package com.sl.yidui_maohao;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * Created by lisulong on 2019/11/1.
 */
public class Demo0 {
    public static void printValur(String str) {
        System.out.println("print value : " + str);
    }

    public static void main(String[] args) {
        Function<String, String> func = String::toUpperCase;
        String result = func.apply("test");
        System.out.println(((Function<String, String>) String::toLowerCase).apply("test=TEST"));

        StringInterface s = String::new;
        String s1 = s.build("123");
        System.out.println(s1);
        //同上的写法
        ((StringInterface) String::new).build("123");

        System.out.println(result);
        List<String> al = Arrays.asList("a", "b", "c", "d");
        al.forEach(Demo0::printValur);
        //下面的方法和上面等价的
        Consumer<String> methodParam = Demo0::printValur; //方法参数
        al.forEach(x -> methodParam.accept(x));//方法执行accept

    }

}

@FunctionalInterface
interface StringInterface {
    // 返回构造对象
    String build(String name);
}